package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class ReturnOperation implements IOPeration{
    @Override
    public void work(BookList booklist) {
        System.out.println("归还图书！");
        System.out.println("请写出您要归还的图书书名");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();

        int currentSize = booklist.getUsedSize();

        for (int i = 0; i < currentSize; i++) {
            Book book = booklist.getBook(i);
            if(book.getName().equals(name)){
                book.setBorrowed(true);
                System.out.println("归还成功！");
                return;
            }
        }
        System.out.println("没有您要归还的图书" + name);
    }
}
